Jump to content

pocobueno1388

Members
  • Posts

    3,369
  • Joined

  • Last visited

    Never

Everything posted by pocobueno1388

  1. I am having some troubles with my news script. What the script is supposed to do is let you fill out a form that asks for the posters name and then they can type out the body of the message and when they submit it it is supposed to add the information to the database then display it to the screen. Here is the URL to the uploaded script I have so far: [a href=\"http://northlakestables.com/dog/news.php\" target=\"_blank\"]http://northlakestables.com/dog/news.php[/a] The problems I am having: 1) Every time you go to that URL above it will add a blank row to the database. I assume I have to exit something in the script, but I am not sure where to do that. 2) When the user uses the form to add news, no matter what they type it, it submits a blank row to the database. 3) Everything in the database is added twice to the screen, I am completely lost on how to stop this. Here is the code I am using. [code] <? include 'config.php'; include 'header.php'; //Get info from the database to post news $sql = "SELECT * FROM news"; $result = mysql_query($sql); //Post the news to the screen while ($row = mysql_fetch_assoc($result)){     print "<br>";     foreach ($row as $col=>$val){         print "<b>$row[poster]</b><p>";         print "$row[body]<hr>";          } } //Print form to add news print<<<HERE     <p><br><br><br> <center><h2>Add News</h2></center> <form action="news.php"> <table border=1>         <td>Username:         <input type = "text"                name = "poster" maxlength=20><p></td> <tr>         <td>Message:<br> <tr>         <td><textarea wrap=virtual rows=12 cols=35 name="body"></textarea></td><br> <tr>         <td align="center"><input type ="submit" valu="Submit"></td> </table> </form> HERE; //Insert post to the database. mysql_query("INSERT INTO news (poster, body)         VALUES ('$poster', '$body')")         or die(mysql_error()); ?> [/code] If anyone can 'fix up' my script or just let me know what to do with it that would be great. I am fairly new to programming, so I am not even sure if I displayed the data to the screen the right way. If I forgot to add anything, just let me know what information you need and I will get it to you asap. Thanks in advance! =D Hopefully I am not asking for too much.
  2. poirot has solved all my problems =D I have gotten so many things done today, thanks to poirot. -worships- Thank you so much. I should have caught that error myself, but I am rather new...so my eyes are not trained enough yet to see those kinds of mistakes. I am sure I will be needing help again soon with something else, I will probably be having a lot more questions as I go through my current project.
  3. businessman332211 - When I do that the entire page just goes blank. So they obviously need to be there. This is so frustrating.
  4. I guess I don't understand. The values will be what the user enters, so I really can't give you a straight answer on that.
  5. I really want to get started, so I really want someone to help me :/
  6. Here is the query: $sql = mysql_query("INSERT INTO users (loginname, username, password, vpassword, email) VALUES('$loginname', '$username', '$password', '$vpassword', '$email'") or die (mysql_error()); Here is the error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4
  7. <?php include "config.php"; include "header.php"; if($_POST['login_name']){ // Define post fields into simple variables $loginname = $_POST['login_name']; $username = $_POST['username']; $password = $_POST['password']; $vpassword = $_POST['vpassword']; $email = $_POST['email']; /* Let's strip some slashes in case the user entered any escaped characters. */ $loginname = stripslashes($login_name); $username = stripslashes($username); $password = stripslashes($password); $vpassword = stripslashes($vpassword); $email = stripslashes($email); /* Do some error checking on the form posted fields */ if((!$loginname) || (!$username) || (!$password) || (!$email)){ echo 'You did not submit the following required information! <br />'; if(!$login_name){ echo "Login Name is a required field. Please enter it below.<br />"; } if(!$username){ echo "Desired Username is a required field. Please enter it below.<br />"; } if(!$password){ echo "Password is a required field. Please enter it below. "; } if(!$email){ echo "Email is a required field. Please enter it below.<br />"; } include 'join_form.html'; // Show the form again! /* End the error checking and if everything is ok, we'll move on to creating the user account */ exit(); // if the error checking has failed, we'll exit the script! } /* Let's do some checking and ensure that the user's email address or username does not exist in the database */ $sql_email_check = mysql_query("SELECT email FROM players WHERE email='$email'"); $sql_username_check = mysql_query("SELECT username FROM players WHERE username='$username'"); $email_check = mysql_num_rows($sql_email_check); $username_check = mysql_num_rows($sql_username_check); if(($email_check > 0) || ($username_check > 0)){ echo "Please fix the following errors: <br />"; if($email_check > 0){ echo "<strong>Your email address has already been used by another member in our database. Please submit a different Email address!<br />"; unset($email_address); } if($username_check > 0){ echo "The username you have selected has already been used by another member in our database. Please choose a different Username!<br />"; unset($username); } include 'join_form.html'; // Show the form again! exit(); // exit the script so that we do not create this account! } /* Everything has passed both error checks that we have done. It's time to create the account! */ // Enter info into the Database. $info2 = htmlspecialchars($info); $sql = mysql_query("INSERT INTO users (loginname, username, password, vpassword, email) VALUES('$loginname', '$username', '$password', '$vpassword', '$email'") or die (mysql_error()); if(!$sql){ echo 'There has been an error creating your account. Please contact the webmaster.'; } else { $userid = mysql_insert_id(); // Let's mail the user! $subject = "Dog Game"; $message = "Hello $username, Thank you for registering at our website, www..com you will be able to login with the following information: Username: $username Password: $password Thanks! Colin (Game Owner/creator) This is an automated response, please do not reply!"; mail($email, $subject, $message, "From: Dogs Webmaster<colin@mydomain.com>\n X-Mailer: PHP/" . phpversion()); echo 'Your membership information has been mailed to your email address! Please check it and follow the directions!'; } exit; } ?> <form name="form1" method="post" action="join_form.php"> <table border="0" cellpadding="4" cellspacing="0" width="100%" valign="center"> <tbody><tr> <td align="left" valign="top" width="24%">Login Name</td> <td width="76%"><input name="login_name" id="loginname" value="" type="text"></td> </tr> <tr> <td align="left" valign="top">Desired Username</td> <td><input name="username" id="username" value="" type="text"></td> </tr> <tr> <td align="left" valign="top">Password</td> <td><input name="password" id="password" value="" type="password"></td> </tr> <tr> <td align="left" valign="top">Re-type Password</td> <td><input name="vpassword" id="vpassword" value="" type="password"></td> </tr> <tr> <td align="left" valign="top">Email</td> <td><input name="email" id="email" value="" type="text"></td> </tr> <tr> <td align="left" valign="top">&nbsp;</td> <td><input name="Submit" value="Join Now!" type="submit"></td> </tr> </tbody></table> </form>
  8. Well...I am trying to access the table through php, but I am sure I don't have it wrong. Why would I need to create the table using PHP when I already have it created? I know how to build a table from scratch with SQL, but not with php. So I guess I am not sure what to do with your advice.
  9. I am using Phpmyadmin to build my tables, but yet when I submit a form from my website to add information in my tables I get this error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4 I did not manually create this SQL, so I don't know how phpmyadmin could mess it up. Is this an SQL problem or is it my script? From the error message it seems like the SQL and database is where the problem is. If you could help me with this, that woud be great. By the way, I am hosting with godaddy.com, not sure if that will help or not. Maybe they don't support something. I don't know. I a fairly new to programming, but I didn't know I could have a problem like this with phpmyadmin(if that is really the problem.). Thanks in advance for you help =D
  10. Okay...I will hunt around for that information. Hopefully that is the only problem, I am anxious to get started on my new project.
  11. Crayon Violent --> Here is the error I got with your code. Can't connect to MySQL server on 'localhost' (10061) joquius--> I got the same error when I took away the quotes. Any other ideas?
  12. I am having trouble getting connected to my database. Here is the code I am using to do it: config.PHP ------------- <?php $host = "localhost"; // your MySQL host i.e. the server on which the database is, usually localhost $user = "*****"; // your MySQL username $pass = "*****"; // your MySQL password $db = "*****"; // the database to which you're trying to connect to $conn = mysql_connect("$host", "$user", "$pass") or die ("Unable to connect to database."); mysql_select_db("$db", $conn); ?> Of course there are actual values stored in the variables other then the '*****'. Is there something wrong with this script? I just use the code include "config.php"; on the top of every script I need it with and it won't work. Any help would be appreciated. Thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.