krabople Posted March 25, 2007 Share Posted March 25, 2007 Hi, I have just attempted my first php script. The script is designed to take information passed from a form on the page before it and then append it into a table in a database. However, when I run it I don't get any error messages or anything, just a blank screen. When I check the database it hasn't updated. Could someone please look through my code and tell me where I'm going wrong? Any advice would be greatly appreciated! [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/44211-need-help-with-my-first-php-script/ Share on other sites More sharing options...
papaface Posted March 25, 2007 Share Posted March 25, 2007 Show us the code then. Link to comment https://forums.phpfreaks.com/topic/44211-need-help-with-my-first-php-script/#findComment-214721 Share on other sites More sharing options...
Timma Posted March 25, 2007 Share Posted March 25, 2007 His code is: (T'was a download) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Registration Result</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <?php $dbcnx = @mysql_connect('localhost', 'root', 'pojipoo'); if (!$dbcnx) { exit('<p>Unable to connect to the database server at this time.</p>'); } if (!mysql_select_db('krabople')) { exit('<p>Unable to locate the krabople database at this time.</p>'); } if (isset($_POST['Username'])) { $title = $_POST['title']; $username = $_POST['username']; $password = $_POST['password']; $address1 = $_POST['address1']; $address2 = $_POST['address2']; $town = $_POST['town']; $postcode = $_POST['postcode']; $homephone = $_POST['homephone']; $mobile = $_POST['mobile']; $dob = $_POST['DOB']; $sql = "INSERT INTO Users SET Username='$username', Password='$password', Address1='$address1', Address2='$address2', Town='$town', Postcode='$postcode', Homephone='$homephone', Mobile='$mobile', DOB='$dob'"; if(@mysql_query($sql)) { echo '<p>Your registration was successful!</p>'; } else { echo '<p>There was an error while processing your registration: ' . mysql_error() . '</p>'; } } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/44211-need-help-with-my-first-php-script/#findComment-214727 Share on other sites More sharing options...
kenrbnsn Posted March 25, 2007 Share Posted March 25, 2007 When you're developing, don't use the "@" which suppresses error messages. Change this: <?php if(@mysql_query($sql)) { echo '<p>Your registration was successful!</p>'; } else { echo '<p>There was an error while processing your registration: ' . mysql_error() . '</p>'; } ?> to <?php $rs = mysql_query($sql) or die ("There was an error while processing your registration with the query <pre>$sql</pre><br>" . mysql_error()); '<p>Your registration was successful!</p>'; ?> This should tell you if the query is in error. Ken Link to comment https://forums.phpfreaks.com/topic/44211-need-help-with-my-first-php-script/#findComment-214739 Share on other sites More sharing options...
krabople Posted March 25, 2007 Author Share Posted March 25, 2007 Hi, thanks for the advice. However, I have tried changing the code as suggested and nothing happens. The annoying thing is that there is no error message whatsoever, just a blank screen. I know that php is definitely working on my computer as I have tried deleting everything and just displaying variables using the echo command. Any idea why the screen might be completely blank? If I miss a bracket or something it tells me there is an error but it is not doing that so I presume the problem is not with the syntax Link to comment https://forums.phpfreaks.com/topic/44211-need-help-with-my-first-php-script/#findComment-214786 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.