Php code problems

This is a discussion on "Php code problems" within the PHP Forum section. This forum, and the thread "Php code problems are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Oct 10th, 2007, 15:22
Reputable Member
Join Date: Oct 2007
Location: Liverpool UK
Age: 29
Posts: 228
Thanks: 0
Thanked 0 Times in 0 Posts
Php code problems

I am trying to get data from my text field to go into my database from my form located on my php page. Its a experiment, the error logs are saying i have syntax errors on lines 34 and 36.

Could some one explain what i am doing wrong.

Its only 1 text box and a tiny database, so its should be easy to spot n fix.

here is my code:

And under that is my database

PHP: Select all

<?php require_once('Connections/dblearn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}
if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
 
$insertSQL sprintf("INSERT INTO tbl_data (name) VALUES (%s)",
              
GetSQLValueString($_POST['name'], "int"), 
     
     
mysql_select_db($database_dblearn$dblearn);
     
$Result1 mysql_query($insertSQL$dblearn) or die(mysql_error());
     
     
$insertGoTo "Customer Data.php";
     if (isset(
$_SERVER['QUERY_STRING'])) {
              
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
              
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
  
header(sprintf("Location: %s"$insertGoTo));
}
mysql_select_db($database_dblearn$dblearn);
$query name "SELECT * FROM tbl_data ORDER BY imid ASC";
$name mysql_query($query name$dblearn) or die(mysql_error());
$row name mysql_fetch_assoc($ name);
$totalRows name mysql_num_rows($ name);
 
 
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p>Please Insert Your Name Below</p>
<form id="form1" name="form1" method="POST">
  <label>
  <input type="text" name="Name Insert Field" id="Name Insert Field" />
  </label>
</form>
<form id="form2" name="form2" method="post" action="">
  <label>
  <input type="submit" name="Button" id="Button" value="Submit" />
  </label>
</form>
<p>&nbsp; </p>
</body>
</html>
<?php
mysql_free_result
($Recordset1);
?>




Here my database:

CREATE DATABASE IF NOT EXISTS dblearn;
USE dblearn;
CREATE TABLE tbl_data (name VARCHAR(20), address VARCHAR(50), post_code VARCHAR(7), telephone_no VARCHAR(25));


Please help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Oct 10th, 2007, 18:52
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Php code problems

Quote:
$insertSQL = sprintf("INSERT INTO tbl_data (name) VALUES (%s)",
GetSQLValueString($_POST['name'], "int"),

mysql_select_db($database_dblearn, $dblearn);
It looks like the middle two lines shoe above may be corrupted from what you expect - I would expect to see the first of them close with a ");" rather than a ",". The problem reports in the following non-blank statement as the line I've just commented on doesn't end correctly
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Oct 10th, 2007, 20:47
Reputable Member
Join Date: Oct 2007
Location: Liverpool UK
Age: 29
Posts: 228
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Php code problems

Cheers Buddy, i written the code out a different way, and it worked, bit thanks anyway dude.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
what are the potential problems taking over another developers code? marsbar PHP Forum 3 Jan 31st, 2008 16:03
[SOLVED] Php code problems longstand PHP Forum 3 Oct 15th, 2007 10:53
live search code and styleswitcher code hebel JavaScript Forum 0 May 12th, 2007 06:16
Can somebody give me the code to hide the source code? renren JavaScript Forum 7 Mar 7th, 2006 12:27
Newbie having problems w/code in O'Reilly book Sqrlgrl PHP Forum 5 May 31st, 2005 10:19


All times are GMT. The time now is 23:52.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42